package com.example.lx5_22.fg

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.example.base.mvvm.BaseFragment
import com.example.lx5_22.R
import com.example.lx5_22.adapter.NoticeAdapter
import com.example.lx5_22.databinding.FragmentHomeBinding
import com.example.lx5_22.news.NoticeViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@AndroidEntryPoint
class HomeFragment : BaseFragment<FragmentHomeBinding, NoticeViewModel>() {

    val noticeAdapter by lazy { NoticeAdapter() }
    override fun initView() {
        binding.llPark.setOnClickListener {
            ARouter.getInstance().build("/app/PackingActivity").navigation()
        }
    }

    override fun initData() {
        binding.rv.apply {
            adapter = noticeAdapter
            layoutManager = LinearLayoutManager(requireContext())
        }
        lifecycleScope.launch {
            viewModel.getNotices().collect{
                noticeAdapter.submitData(it)
            }
        }
    }
}